package com.cykj.pos.controller.api;

import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.core.page.TableDataInfo;
import com.cykj.common.enums.BusinessType;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.pos.domain.FeiShunSettlement;
import com.cykj.pos.service.IFeiShunSettlementService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 结算信息Controller
 *
 * @author weijianbo
 * @date 2024-02-04
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/settlement" )
public class FeiShunSettlementController extends BaseController {

    private final IFeiShunSettlementService iFeiShunSettlementService;

    /**
     * 查询结算信息列表
     */
    @PreAuthorize("@ss.hasPermi('pos:settlement:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeiShunSettlement feiShunSettlement) {
        startPage();
        List<FeiShunSettlement> list = iFeiShunSettlementService.queryList(feiShunSettlement);
        return getDataTable(list);
    }

    /**
     * 导出结算信息列表
     */
//    @PreAuthorize("@ss.hasPermi('pos:settlement:export')" )
    @Log(title = "结算信息" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(FeiShunSettlement feiShunSettlement) {
        List<FeiShunSettlement> list = iFeiShunSettlementService.queryList(feiShunSettlement);
        ExcelUtil<FeiShunSettlement> util = new ExcelUtil<FeiShunSettlement>(FeiShunSettlement.class);
        return util.exportExcel(list, "settlement" );
    }

    /**
     * 获取结算信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:settlement:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iFeiShunSettlementService.getById(id));
    }

    /**
     * 新增结算信息
     */
    @PreAuthorize("@ss.hasPermi('pos:settlement:add')" )
    @Log(title = "结算信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeiShunSettlement feiShunSettlement) {
        return toAjax(iFeiShunSettlementService.save(feiShunSettlement) ? 1 : 0);
    }

    /**
     * 修改结算信息
     */
//    @PreAuthorize("@ss.hasPermi('pos:settlement:edit')" )
    @Log(title = "结算信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeiShunSettlement feiShunSettlement) {

        return iFeiShunSettlementService.submitSett(feiShunSettlement);
    }

    /**
     * 删除结算信息
     */
    @PreAuthorize("@ss.hasPermi('pos:settlement:remove')" )
    @Log(title = "结算信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iFeiShunSettlementService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
